<!-- <template>
  <el-badge is-dot class="item">query</el-badge>
</template>


<style scoped>
.item {
  margin-top: 10px;
  margin-right: 40px;
}
</style> -->
<!-- <script lang="ts" setup>
import { reactive, ref } from 'vue'
import type { FormItemProps, FormProps } from 'element-plus'



const labelPosition = ref<FormProps['labelPosition']>('right')
const itemLabelPosition = ref<FormItemProps['labelPosition']>('')
const formLabelAlign = reactive({
  oldPassWord: '',
  newPassword: '',
  reNewPassword: '',
})
const checkRePassword=(rule,value,callback)=>{
  if(value===''){
    callback(new Error('请再次确认密码'));
  }else if(value!==formLabelAlign.newPassword){
    callback(new Error('请确保两个的密码相同'));
  }else{
    callback()
  }
}
const rules = {
    oldPassword: [
        { required: true, message: '请输入旧密码', trigger: 'blur' },
        {min:5,max:16,message:'长度为5~16的非空字符',trigger:'blur'}
    ],
    newPassword: [
        { required: true, message: '请输入新密码', trigger: 'blur' },
        {min:5,max:16,message:'长度为5~16的非空字符',trigger:'blur'}
    ],
    reNewPassword:[
      {validator:checkRePassword,trigger:'blur'}
    ]
}
</script>


<template>
  <el-form
    :label-position="labelPosition"
    label-width="auto"
    :model="formLabelAlign"
    style="max-width: 600px"
    :rules="rules"
  >
    <el-form-item label="格式选择" label-position="right">
      <el-radio-group v-model="labelPosition" aria-label="label position">
        <el-radio-button value="left">Left</el-radio-button>
        <el-radio-button value="right">Right</el-radio-button>
        <el-radio-button value="top">Top</el-radio-button>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="表单选择" label-position="right">
      <el-radio-group
        v-model="itemLabelPosition"
        aria-label="item label position"
      >
        <el-radio-button value="">Empty</el-radio-button>
        <el-radio-button value="left">Left</el-radio-button>
        <el-radio-button value="right">Right</el-radio-button>
        <el-radio-button value="top">Top</el-radio-button>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="原密码" :label-position="itemLabelPosition" prop="oldPassword">
      <el-input v-model="formLabelAlign.oldPassWord" />
    </el-form-item>
    <el-form-item label="新密码" :label-position="itemLabelPosition" prop="newPassword">
      <el-input v-model="formLabelAlign.newPassword" />
    </el-form-item>
    <el-form-item label="再次输入" :label-position="itemLabelPosition" prop="reNewPassword">
      <el-input v-model="formLabelAlign.reNewPassword" />
    </el-form-item>
  </el-form>
</template> -->

<script setup>
import { User, Lock } from '@element-plus/icons-vue'
import { ref } from 'vue'
//控制注册与登录表单的显示， 默认显示注册
const isRegister = ref(true)

const formLabelAlign=ref({
  oldPassword: '',
  newPassword: '',
  reNewPassword: ''
})

const checkRePassword=(rule,value,callback)=>{
  if(value===''){
    callback(new Error('请再次确认密码'));
  }else if(value!==formLabelAlign.value.newPassword){
    callback(new Error('请确保两个的密码相同'));
  }else{
    callback()
  }
}
const rules = {
    oldPassword: [
        { required: true, message: '请输入旧密码', trigger: 'blur' },
        {min:5,max:16,message:'长度为5~16的非空字符',trigger:'blur'}
    ],
    newPassword: [
        { required: true, message: '请输入新密码', trigger: 'blur' },
        {min:5,max:16,message:'长度为5~16的非空字符',trigger:'blur'}
    ],
    reNewPassword:[
      {validator: checkRePassword,trigger:'blur'}
    ]
}
import {passwordChangeService}from '@/api/user.js'
const update=async()=>{
  const temp=({
    oldPassword: '',
    newPassword: ''
  })
  temp.oldPassword=formLabelAlign.value.oldPassword
  temp.newPassword=formLabelAlign.value.newPassword
  let result=await passwordChangeService(temp);
  if(result.success===true){
    alert("获取成功")
  }else{
    alert("获取失败")
  }
}
</script>

<template>
    <el-row class="login-page">
        <el-col :span="6" :offset="3" class="form"  >
            <!-- 注册表单 -->
            <el-form ref="form" size="large" autocomplete="off" v-if="isRegister" :rules="rules" :model="formLabelAlign">
                <el-form-item>
                    <h1>注册</h1>
                </el-form-item>
                <el-form-item prop="oldPassword">
                    <el-input :prefix-icon="Lock" type="password" placeholder="请输入旧密码" v-model="formLabelAlign.oldPassword"></el-input>
                </el-form-item>
                <el-form-item prop="newPassword">
                    <el-input :prefix-icon="Lock" type="password" placeholder="请输入新密码" v-model="formLabelAlign.newPassword"></el-input>
                </el-form-item>
                <el-form-item prop="reNewPassword">
                    <el-input :prefix-icon="Lock" type="password" placeholder="请输入再次新密码" v-model="formLabelAlign.reNewPassword"></el-input>
                </el-form-item>
                <!-- 注册按钮 -->
                <el-form-item>
                    <el-button class="button" type="primary" auto-insert-space @click="update">
                        修改
                    </el-button>
                </el-form-item>
            </el-form>
                <el-form-item class="flex">
                    <el-link type="info" :underline="false" @click="isRegister = true">
                        修改 →
                    </el-link>
                </el-form-item>
        </el-col>
    </el-row>
</template>

<style lang="scss" scoped>
/* 样式 */
.login-page {
    height: 100vh;
    background-color: #fff;

    .bg {
        background: url('@/assets/logo2.png') no-repeat 60% center / 240px auto,
            url('@/assets/login_bg.jpg') no-repeat center / cover;
        border-radius: 0 20px 20px 0;
    }

    .form {
        display: flex;
        flex-direction: column;
        justify-content: center;
        user-select: none;

        .title {
            margin: 0 auto;
        }

        .button {
            width: 100%;
        }

        .flex {
            width: 100%;
            display: flex;
            justify-content: space-between;
        }
    }
}
</style>
